package com.wanjia.bpsapi.handler;


import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object handleException(Exception e) {
        String msg = e.getMessage();
        log.error(msg, e);
        if (msg == null || msg.equals("")) {
            msg = "出错啦";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("state", 9999);
        jsonObject.put("message", msg);
        return jsonObject;
    }
}
